Components.utils.import("resource://gre/modules/DbTerminal.jsm");


function windowInit()
{
    
    setWindowTitle();
    dDeviceSqlite.onLoad();
    var listbox =  document.getElementById("thelist");
    var statement = dDeviceSqlite.dbConnection.createStatement("\
                  SELECT dName,dId,dLocation,dUDN FROM td_device where dName = :myVal");
            statement.params.myVal = window.arguments[0];
            //alert(statement.params.myVal);
            while(statement.executeStep()){
                        var dIds=statement.row.dId;
                        var dNames=statement.row.dName; 
                        var dLocations=statement.row.dLocation;
                        var ip = dLocations.split(":")[1].split("/")[2];
                        var dUDNs=statement.row.dUDN;
                       
                        var listitem = document.createElement("listitem");
                        var listcell1 = document.createElement("listcell");
                        var listcell2 = document.createElement("listcell");
                        var listcell3 = document.createElement("listcell");
                        var listcell4 = document.createElement("listcell");
                        listcell1.setAttribute("label",dNames);
                        listitem.appendChild(listcell1);
                        listcell2.setAttribute("label",ip);
                        listitem.appendChild(listcell2);
                        listcell3.setAttribute("label",dUDNs);
                        listitem.appendChild(listcell3);
                        listcell4.setAttribute("label","在线");
                        listitem.appendChild(listcell4);
                        listbox.appendChild(listitem);
                        //alert(listitem.childElementCount);
                       // listbox.appendChild(listitem);
                        
//                        var devString=window.arguments[0].toString();
            
//                        var listcell1 = document.getElementById("one");
//                        listcell1.setAttribute("label",dNames);
//                        var listcell2 = document.getElementById("two");
//                        listcell2.setAttribute("label",ip);
//                         var listcell3 = document.getElementById("three");
//                        listcell3.setAttribute("label",dUDNs);
//                        var listcell4 = document.getElementById("four");
//                        listcell4.setAttribute("label","在线");
                        
                      
                    //  alert(listbox.childElementCount);
                    }
            }
    //createNewTabbox(window.arguments[0]);
    

function setWindowTitle()
{
    var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
    var enumwindow = windowManager.getEnumerator(null);

    while (enumwindow.hasMoreElements()) {
        var win = enumwindow.getNext().QueryInterface(Components.interfaces.nsIDOMChromeWindow);
        if (win.name === "deviceInfo") {
           document.title = "查看" + window.arguments[0].toString() + "设备信息";
        }
    }
}
//function(){setTimeout(function(){windowInit();},0);}
//window.addEventListener('load', windowInit, false);

window.addEventListener("load", function () {
    setTimeout(function () {
        windowInit();
    }, 1);
});